package router

import (
	"backend/middleware"
	"backend/service"
	"github.com/gin-gonic/gin"
)

func Router() *gin.Engine {
	r := gin.Default()
	// 添加跨越中间件
	r.Use(middleware.Cors())
	r.Use(middleware.LoggerToDb())
	r.POST("/login", service.Login)
	loginAuth := r.Group("/").Use(middleware.LoginAuthCheck())
	loginAuth.GET("/getuser", service.GetUserList)
	loginAuth.POST("/adduser", service.AddUser)
	loginAuth.POST("/user/detail", service.GetUserDetail)
	loginAuth.POST("/user/update", service.UpdateUser)
	loginAuth.POST("/user/delete", service.DeleteUser)
	loginAuth.POST("/user/update_password", service.UpdateUserPassword)
	loginAuth.GET("/getrole", service.GetRoleList)
	loginAuth.POST("/role/add", service.AddRole)
	loginAuth.GET("/role/detail", service.GetRoleDetail)
	loginAuth.POST("/role/update", service.UpdateRole)
	loginAuth.POST("/role/delete", service.DeleteRole)
	loginAuth.POST("/role/changeadmin", service.PatchRoleAdmin)
	loginAuth.GET("/role/all", service.AllRole)
	loginAuth.GET("/menu/list", service.GetMenuList)
	loginAuth.POST("/menu/add", service.AddMenu)
	loginAuth.POST("/menu/update", service.UpdateMenu)
	loginAuth.POST("/menu/delete", service.DeleteMenu)
	return r
}
